package cn.semyes.ylipfilter.controller.businessbridge;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.semyes.ylipfilter.common.util.GetCurDateTime;
import cn.semyes.ylipfilter.service.BusinessBridgeService;

@Controller
@RequestMapping("/businessbridge")
public class BusinessBridgeController {
	
	private int user_id = 0;
	private int app_id = 3;
	private String visit_time = null;
	private String create_time = null; 
	
	private GetCurDateTime getCurDateTime;
	
	@Autowired
	private BusinessBridgeService businessBridgeService;
	
	@PostMapping("/save.do")
	@ResponseBody
	public int saveBusinessBridge(HttpServletRequest request,String company_name, String phone_number) {
		getCurDateTime = new GetCurDateTime();
		user_id = Integer.parseInt(request.getSession().getAttribute("cur_bd_userId").toString());
		visit_time = request.getSession().getAttribute("cur_datatime").toString();
		create_time = getCurDateTime.getCurTime();
	
		businessBridgeService.saveUser(user_id,company_name, phone_number,create_time,app_id,visit_time);
		return 1;
	}
	
	@PostMapping("/update.do")
	@ResponseBody
	public int updateBusinessBridge(HttpServletRequest request,String company_name, String phone_number) {
		getCurDateTime = new GetCurDateTime();
		user_id = Integer.parseInt(request.getSession().getAttribute("cur_bd_userId").toString());
		visit_time = request.getSession().getAttribute("cur_datatime").toString();
		create_time = getCurDateTime.getCurTime();
	
		businessBridgeService.updateUser(company_name, phone_number);
		return 1;
	}

}
